<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/24
 * Time: 14:52
 */
namespace app\portal\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalPostModel;
use app\portal\service\PostService;
use app\admin\model\ThemeModel;
use FontLib\Table\Type\post;
use think\Db;
class TransitController extends AdminBaseController
{
    public function _initialize()
    {

    }
    public function index(){
        if($param = $this->request->param('keyword')){
            $data=Db::name('link_logistics')->where(['order_id'=>$param])->select();
            $this->assign('data',$data);
            return $this->fetch('index');
        }
        $data=Db::name('link_logistics')->select();
        $this->assign('data',$data);
        return $this->fetch('index');
    }
    //添加记录
    public function add_logistics(){
        if($this->request->isPost()){
            $data['order_id']=$_POST['order_id'];
            //跳或者不跳
            if($this->request->param('flag')=='1'){
                $data['start_time']=$_POST['start_time'];
                $data['dynamic']=$_POST['dynamic'];
                Db::name('logistics')->insert($data);
                $this->assign('logistics',Db::name('logistics')->where('order_id',$_POST['order_id'])->select());
                $this->assign('order_id',$data['order_id']);
                return $this->fetch('add_logistics');
            }else{
                if(Db::name('link_logistics')->where('order_id',$_POST['order_id'])->find()){
                    $this->error('该订单号已存在，请按该订单号后追加记录按钮',url('Transit/index'));
                }
                $data['start_time']=$_POST['start_time'];
                $data['dynamic']=$_POST['dynamic'];
                Db::name('link_logistics')->insert(['order_id'=>$_POST['order_id']]);
                Db::name('logistics')->insert($data);
                $this->assign('logistics',Db::name('logistics')->where('order_id',$_POST['order_id'])->select());
                $this->success('添加成功！若继续添加请追加记录',url('Transit/index'));
                exit;
            }
        }else{
            $this->assign('logistics',Db::name('logistics')->where('order_id','10000000000000005')->select());
        }
        return $this->fetch('add_logistics');
    }
    //追加记录
    public function additional_log(){
      
        $id = $this->request->param('order_id');
        $this->assign('order_id',$id);
        $this->assign('logistics',Db::name('logistics')->where('order_id',$id)->select());
        return $this->fetch('add_logistics');
    }
}